package com.yxy.controller;

import com.yxy.base.BusinessException;
import com.yxy.base.RestResponse;
import com.yxy.dto.system.TenantListDto2;
import com.yxy.model.TenantExtend;
import com.yxy.service.TenantService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author yuxiaoyang
 * 租户管理
 */
@RestController
@Slf4j
@RequestMapping("/tenant")
public class TenantController {

  @Autowired
  private TenantService functionService;

  // 获取列表,需要与union auth进行同步
  @PostMapping("/list")
  public RestResponse getList(@RequestBody TenantListDto2 inputDto) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(functionService.getList(inputDto));
    return restResponse;
  }

  //修改 租户, 不能创建
  @PostMapping("/update")
  public RestResponse update(@RequestBody @Valid TenantExtend inputDto) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(functionService.update(inputDto));
    return restResponse;
  }
}
